<?php

namespace App\Http\Controllers\Site;

use App\B2BProject\Custom\Business\GoodsCategory;
use App\B2BProject\Custom\Provider\Offer;
use App\B2BProject\Site\HelperControllerBuildTrait;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Redirect;

class SearchResultController extends Controller
{
    use HelperControllerBuildTrait;

    /**
     * 返回搜索相关信息
     * @param Request $request
     * @return $this|\Illuminate\View\View
     */
    public function postIndex(Request $request)
    {
        $inputText = $request->input('input_text');
        if (GoodsCategory::where('name', 'like', "%$inputText%")->where('parent_id', '!=', 0)->first()) {

            foreach (GoodsCategory::where('name', 'like', "%$inputText%")->where('parent_id', '!=',
                0)->get() as $parent) {
                $category = $parent->id;
            }
            $parent_id = 1;
            //供应
            if ($request->input('id') == '1') {
                return view('host/provider')->with('pid', $parent_id)->with('cid', $category);
            } //求购
            elseif ($request->input('id') == '2') {
                return view('host/purchaser')->with('pid', $parent_id)->with('cid', $category);
            } //商家
            else {
                return view('host/merchant')->with('pid', $parent_id)->with('cid', $category);
            }
        } else {
            //供应
            if ($request->input('id') == '1') {
                return view('host/provider')->with('pid', 0)->with('cid', 0);
            } //求购
            elseif ($request->input('id') == '2') {
                return view('host/purchaser')->with('pid', 0)->with('cid', 0);
            } //商家
            else {
                return view('host/merchant')->with('pid', 0)->with('cid', 0);
            }
        }

    }
}
